home *** CD-ROM | disk | FTP | other *** search
- /*
- File: AVTransportTrafficLight.c
-
- Contains: Application software to control AV transport mechanisms.
-
- Written by: Erik Staats with help from DTS.
-
- Copyright: © 1996-1997 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <FW10> 3/18/97 ES Changed to not create new window if we get device added
- notification for a device we already have open.
- <FW9> 2/7/97 ES Added call to GetNextAVTClientEvent in event loop.
- <FW8> 8/26/96 ES Changed to call QuitApplication if we quit on error.
- <FW7> 8/1/96 ES Took out unused local variables.
- <FW6> 7/31/96 ES Added dumpBufferOffset to avtDumpParams.
- <FW5> 7/8/96 ES Added extra menu and added snap shot grabbing and playing
- capabilities.
- <FW4> 6/21/96 ES Changed some of the window stuff so this will work with MPW 3.4.
- <FW3> 6/20/96 ES Modified contains field.
- <FW2> 6/20/96 ES Filled in contains and written by fields.
- <FW1> 6/20/96 ES first checked in
-
- */
-
- #include <Types.h>
- #include <Memory.h>
- #include <Devices.h>
- #include <Resources.h>
- #include <QuickDraw.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <AppleEvents.h>
- #include <EPPC.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <Dialogs.h>
- #include <ToolUtils.h>
- #include <DiskInit.h>
- #include <AVTransport.h>
- #include <AVTransportTrafficLight.h>
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Define global structure to hold all of the AVTTrafficLight data.
- //
-
- AVTTrafficLightAppDataPtr gpAVTTrafficLightAppData = nil;
- Boolean quitTrafficLightApp = false;
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Internal procedure prototypes.
- //
-
- static void AVTTrafficLightEventLoop (void);
-
- static OSErr HandleEvent (
- EventRecord *pEventRecord);
-
- static OSErr HandleMouseDownEvent (
- EventRecord *pEventRecord);
-
- static OSErr HandleKeyEvent (
- EventRecord *pEventRecord);
-
- static OSErr HandleOSEvent (
- EventRecord *pEventRecord);
-
- static OSErr HandleMenuCommand (
- long menuCommand);
-
- static OSErr HandleAppleMenuCommand (
- short menuItem);
-
- static OSErr HandleFileMenuCommand (
- short menuItem);
-
- static OSErr HandleExtraMenuCommand (
- short menuItem);
-
- static OSErr HandleCloseFileMenuCommand (void);
-
- static OSErr CaptureSnapShot (void);
-
- static OSErr PlaySnapShot (void);
-
- static OSErr StopSnapShot (void);
-
- static OSErr HandleWindowCommand (
- WindowRef windowRef);
-
- static OSErr AVTTrafficLightInitialize (void);
-
- static OSErr QuitApplication (void);
-
- static OSErr CreateTrafficLight (
- AVTDriverID avtDriverID);
-
- static OSErr RemoveTrafficLight (
- AVTDriverID avtDriverID);
-
- static OSErr CloseTrafficLightWindow (
- WindowRef windowRef);
-
- static OSErr DrawTrafficLight (
- WindowRef windowRef);
-
- static OSErr SetTrafficLightState (
- WindowRef windowRef,
- Boolean stopped);
-
- static Boolean GetTrafficLightState (
- WindowRef windowRef);
-
- static OSErr UpdateWindow (
- WindowRef windowRef);
-
- static OSErr UpdateMenus (void);
-
- static OSErr UpdateCursor (
- Point mousePosition,
- RgnHandle hCursorRgn);
-
- static Boolean IsTrafficLightWindow (
- WindowRef windowRef);
-
- static void GetMousePosition (
- Point *pMousePosition);
-
- static pascal OSErr HandleOpenApplicationEvent (
- AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefcon);
-
- static pascal OSErr HandleOpenDocumentsEvent (
- AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefcon);
-
- static pascal OSErr HandlePrintDocumentsEvent (
- AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefcon);
-
- static pascal OSErr HandleQuitApplicationEvent (
- AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefcon);
-
- static pascal OSErr HandleDeviceAddedEvent (
- AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefcon);
-
- static pascal OSErr HandleDeviceRemovedEvent (
- AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefcon);
-
- static TrafficLightDataPtr FindTrafficLightFromAVTDriver (
- AVTDriverID avtDriverID);
-
- static OSErr RemoveTrafficLightFromList (
- TrafficLightDataPtr pTrafficLightData);
-
- static OSErr PrepareWindowForUpdating (
- WindowRef windowRef,
- Boolean *pUpdateNeeded);
-
- static OSErr ReleaseWindowFromUpdating (
- WindowRef windowRef);
-
-
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Exported routines.
- //
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // AVTTrafficLightMain
- //
- // This routine is the main entry point for the AVTransportTrafficLight
- // application.
- //
-
- AVTTrafficLightMain()
- {
- OSErr err = noErr;
-
- // Initialize the application.
- err = AVTTrafficLightInitialize ();
-
- // Main application event loop.
- if (err == noErr)
- AVTTrafficLightEventLoop ();
-
- // Dispose of app data.
- if (gpAVTTrafficLightAppData != nil)
- QuitApplication ();
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Internal routines.
- //
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // AVTTrafficLightEventLoop
- //
- // This routine is the main event loop for the AVTransportTrafficLight
- // application.
- //
-
- static void AVTTrafficLightEventLoop(void)
- {
- RgnHandle hCursorRgn;
- Point mousePosition;
- EventRecord eventRecord;
- Boolean gotEvent;
- OSErr err = noErr;
-
- // Initialize cursor region.
- hCursorRgn = NewRgn ();
- if (hCursorRgn == nil)
- err = memFullErr;//zzz is this right?
-
- // Main event loop.
- while ((!quitTrafficLightApp) && (err == noErr))
- {
- // Update cursor to correct image.
- GetMousePosition (&mousePosition);
- err = UpdateCursor (mousePosition, hCursorRgn);
-
- // Get any AVTransport events.
- if (err == noErr)
- err = GetNextAVTClientEvent (gpAVTTrafficLightAppData->avtClientID);
-
- // Wait for next event.
- if (err == noErr)
- gotEvent = WaitNextEvent (everyEvent, &eventRecord, 0, hCursorRgn);
-
- // Handle event if we got one.
- if (err == noErr)
- {
- if (gotEvent)
- {
- // Update cursor to correct image.
- err = UpdateCursor (eventRecord.where, hCursorRgn);
-
- // Handle the event.
- if (err == noErr)
- err = HandleEvent (&eventRecord);
- }
- }
- }
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleEvent
- //
- // This routine handles the given event.
- //
-
- static OSErr HandleEvent(
- EventRecord *pEventRecord)
- {
- Point point;
- OSErr err = noErr;
-
- // Main event dispatcher.
- switch (pEventRecord->what)
- {
- case mouseDown :
- err = HandleMouseDownEvent (pEventRecord);
- break;
-
- case keyDown :
- case autoKey :
- err = HandleKeyEvent (pEventRecord);
- break;
-
- case updateEvt :
- err = UpdateWindow ((WindowRef) (pEventRecord->message));
- break;
-
- case diskEvt :
- if ((pEventRecord->message >> 16) != noErr)
- {
- SetPt (&point, kDILeft, kDITop);
- err = DIBadMount (point, pEventRecord->message);
- }
- break;
-
- case osEvt :
- err = HandleOSEvent (pEventRecord);
- break;
-
- case kHighLevelEvent :
- AEProcessAppleEvent (pEventRecord);
- break;
-
- default :
- break;
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleMouseDownEvent
- //
- // This routine handles mouse down events.
- //
-
- static OSErr HandleMouseDownEvent(
- EventRecord *pEventRecord)
- {
- WindowRef windowRef;
- short inPart;
- OSErr err = noErr;
-
- // Find out what part of application mouse is in.
- inPart = FindWindow (pEventRecord->where, &windowRef);
-
- // Dispatch off of inPart.
- switch (inPart)
- {
- case inMenuBar :
- UpdateMenus ();
- err = HandleMenuCommand (MenuSelect (pEventRecord->where));
- break;
-
- case inSysWindow :
- SystemClick (pEventRecord, windowRef);
- break;
-
- case inContent :
- if (windowRef == FrontWindow ())
- err = HandleWindowCommand (windowRef);
- else
- SelectWindow (windowRef);
- break;
-
- case inDrag :
- DragWindow
- (windowRef,
- pEventRecord->where,
- &(gpAVTTrafficLightAppData->qdGlobals.screenBits.bounds));
- break;
-
- case inGoAway :
- if (TrackGoAway (windowRef, pEventRecord->where))
- CloseTrafficLightWindow (windowRef);
- break;
-
- default :
- break;
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleKeyEvent
- //
- // This routine handles key events.
- //
-
- static OSErr HandleKeyEvent(
- EventRecord *pEventRecord)
- {
- char key;
- OSErr err = noErr;
-
- // Read the key from the event record.
- key = pEventRecord->message & charCodeMask;
-
- // We're only interested in command key down events.
- if ((pEventRecord->modifiers & cmdKey) &&
- (pEventRecord->what == keyDown))
- {
- UpdateMenus ();
- err = HandleMenuCommand (MenuKey (key));
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleOSEvent
- //
- // This routine handles OS events.
- //
-
- static OSErr HandleOSEvent(
- EventRecord *pEventRecord)
- {
- UInt32 osEventType;
- OSErr err = noErr;
-
- // Get the OS event type.
- osEventType = pEventRecord->message >> 24;
-
- // Dispatch.
- switch (osEventType)
- {
- case suspendResumeMessage :
- if (pEventRecord->message & resumeFlag)
- gpAVTTrafficLightAppData->inForeground = true;
- else
- gpAVTTrafficLightAppData->inForeground = false;
- break;
-
- default :
- break;
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleMenuCommand
- //
- // This routine handles menu commands.
- //
-
- static OSErr HandleMenuCommand(
- long menuCommand)
- {
- short menuID,
- menuItem;
- OSErr err = noErr;
-
- // Get menu ID and item number from the menu command.
- menuID = menuCommand >> 16;
- menuItem = menuCommand & 0xFFFF;
-
- // Dispatch off of menu ID.
- switch (menuID)
- {
- case kAppleMenuID :
- err = HandleAppleMenuCommand (menuItem);
- break;
-
- case kFileMenuID :
- err = HandleFileMenuCommand (menuItem);
- break;
-
- case kEditMenuID :
- // Don't know if we'll ever get here.
- SystemEdit (menuItem - 1);
- break;
-
- case kExtraMenuID :
- err = HandleExtraMenuCommand (menuItem);
- break;
-
- default :
- break;
- }
-
- // Unhilite menu.
- HiliteMenu (0);
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleAppleMenuCommand
- //
- // This routine handles apple menu commands.
- //
-
- static OSErr HandleAppleMenuCommand(
- short menuItem)
- {
- Str255 daName;
- OSErr err = noErr;
-
- // Apple menu dispatch.
- switch (menuItem)
- {
- case kAboutAppleMenuItem :
- Alert (kAboutAlertResourceID, nil);
- break;
-
- default :
- // All non-about items are DAs.
- GetMenuItemText (GetMenuHandle (kAppleMenuID), menuItem, daName);
- OpenDeskAcc (daName);
- break;
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleFileMenuCommand
- //
- // This routine handles file menu commands.
- //
-
- static OSErr HandleFileMenuCommand(
- short menuItem)
- {
- OSErr err = noErr;
-
- // File menu dispatch.
- switch (menuItem)
- {
- case kCloseFileMenuItem :
- HandleCloseFileMenuCommand ();
- break;
-
- case kQuitFileMenuItem :
- QuitApplication ();
- break;
-
- default :
- break;
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleExtraMenuCommand
- //
- // This routine handles extra menu commands.
- //
-
- static OSErr HandleExtraMenuCommand(
- short menuItem)
- {
- OSErr err = noErr;
-
- // File menu dispatch.
- switch (menuItem)
- {
- case kCaptureSnapShotMenuItem :
- err = CaptureSnapShot ();
- break;
-
- case kPlaySnapShotMenuItem :
- err = PlaySnapShot ();
- break;
-
- case kStopSnapShotMenuItem :
- err = StopSnapShot ();
- break;
-
- default :
- break;
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleCloseFileMenuCommand
- //
- // This routine handles the close command.
- //
-
- static OSErr HandleCloseFileMenuCommand(void)
- {
- WindowRef windowRef;
- OSErr err = noErr;
-
- // Get reference to front most window and close.
- windowRef = FrontWindow ();
- if (windowRef != kInvalidWindowRef)
- err = CloseTrafficLightWindow (windowRef);
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // CaptureSnapShot
- //
- // This routine captures a snap shot picture from the camera.
- //
-
- static OSErr CaptureSnapShot(void)
- {
- WindowRef windowRef;
- MenuHandle hMenu;
- TrafficLightDataPtr pTrafficLightData;
- AVTDumpParams avtDumpParams;
- OSErr err = noErr;
-
- // Get reference to front most window and close.
- windowRef = FrontWindow ();
- if (windowRef != kInvalidWindowRef)
- {
- // Get traffic light data.
- pTrafficLightData = (TrafficLightDataPtr) GetWRefCon (windowRef);
-
- // Stop playing snap shot if it's playing.
- if (pTrafficLightData->snapShotPlaying)
- err = StopSnapShot ();
-
- // Capture a snap shot.
- if (err == noErr)
- {
- avtDumpParams.avtInterfaceParams.interfaceSelector =
- kAVTransportDump;
- avtDumpParams.dumpBuffer =
- gpAVTTrafficLightAppData->dumpBuffer;
- avtDumpParams.dumpBufferSize =
- gpAVTTrafficLightAppData->dumpBufferSize;
- avtDumpParams.dumpBufferOffset = 0;
-
- err = CallAVTDriver
- (pTrafficLightData->avtDriverID,
- (AVTInterfaceParamsPtr) &avtDumpParams);
- }
-
- // Enable playing snap shot if we hadn't already gotten one.
- if ((err == noErr) && (!(gpAVTTrafficLightAppData->gotSnapShot)))
- {
- hMenu = GetMenuHandle (kExtraMenuID);
-
- if (hMenu != nil)
- {
- EnableItem (hMenu, kPlaySnapShotMenuItem);
- gpAVTTrafficLightAppData->gotSnapShot = true;
- }
- }
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // PlaySnapShot
- //
- // This routine plays a snap shot picture to the camera.
- //
-
- static OSErr PlaySnapShot(void)
- {
- WindowRef windowRef;
- MenuHandle hMenu;
- TrafficLightDataPtr pTrafficLightData;
- AVTPlaySnapShotParams avtPlaySnapShotParams;
- OSErr err = noErr;
-
- // Get reference to front most window and close.
- windowRef = FrontWindow ();
- if (windowRef != kInvalidWindowRef)
- {
- // Get traffic light data.
- pTrafficLightData = (TrafficLightDataPtr) GetWRefCon (windowRef);
-
- // Play a snap shot.
- if ((!(pTrafficLightData->snapShotPlaying)) &&
- (gpAVTTrafficLightAppData->gotSnapShot))
- {
- avtPlaySnapShotParams.avtInterfaceParams.interfaceSelector =
- kAVTransportPlaySnapShot;
- avtPlaySnapShotParams.snapShotBuffer =
- gpAVTTrafficLightAppData->dumpBuffer;
- avtPlaySnapShotParams.snapShotBufferSize =
- gpAVTTrafficLightAppData->dumpBufferSize;
-
- err = CallAVTDriver
- (pTrafficLightData->avtDriverID,
- (AVTInterfaceParamsPtr) &avtPlaySnapShotParams);
-
- // Enable stopping snap shot.
- if (err == noErr)
- {
- hMenu = GetMenuHandle (kExtraMenuID);
- if (hMenu != nil)
- {
- DisableItem (hMenu, kPlaySnapShotMenuItem);
- EnableItem (hMenu, kStopSnapShotMenuItem);
- }
-
- pTrafficLightData->snapShotPlaying = true;
- }
- }
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // StopSnapShot
- //
- // This routine stops playing a snap shot picture to the camera.
- //
-
- static OSErr StopSnapShot(void)
- {
- WindowRef windowRef;
- MenuHandle hMenu;
- TrafficLightDataPtr pTrafficLightData;
- AVTInterfaceParams avtInterfaceParams;
- OSErr err = noErr;
-
- // Get reference to front most window and close.
- windowRef = FrontWindow ();
- if (windowRef != kInvalidWindowRef)
- {
- // Get traffic light data.
- pTrafficLightData = (TrafficLightDataPtr) GetWRefCon (windowRef);
-
- // Play a snap shot.
- if (pTrafficLightData->snapShotPlaying)
- {
- avtInterfaceParams.interfaceSelector = kAVTransportStopSnapShot;
-
- err = CallAVTDriver
- (pTrafficLightData->avtDriverID, &avtInterfaceParams);
-
- // Enable playing snap shot.
- if (err == noErr)
- {
- hMenu = GetMenuHandle (kExtraMenuID);
- if (hMenu != nil)
- {
- DisableItem (hMenu, kStopSnapShotMenuItem);
- EnableItem (hMenu, kPlaySnapShotMenuItem);
- }
-
- pTrafficLightData->snapShotPlaying = false;
- }
- }
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleWindowCommand
- //
- // This routine handles commands in the contents of the window.
- //
-
- static OSErr HandleWindowCommand(
- WindowRef windowRef)
- {
- OSErr err = noErr;
-
- // Toggle the traffic light state.
- err = SetTrafficLightState (windowRef, !(GetTrafficLightState (windowRef)));
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // AVTTrafficLightInitialize
- //
- // This routine initializes the AVTransportTrafficLight application.
- //
-
- static OSErr AVTTrafficLightInitialize(void)
- {
- Handle hMenuBarResource;
- Handle hRectResource;
- AVTDriverID *avtDriverIDList = nil;
- UInt32 numAVTDrivers,
- driverNum;
- Ptr dumpBuffer;
- OSErr err = noErr;
-
- // Create our global data record.
- gpAVTTrafficLightAppData = (AVTTrafficLightAppDataPtr)
- NewPtrClear (sizeof (AVTTrafficLightAppData));
- if (gpAVTTrafficLightAppData != nil)
- {
- gpAVTTrafficLightAppData->avtClientID = kInvalidAVTClientID;
- gpAVTTrafficLightAppData->inForeground = true;
- }
- else
- {
- err = memFullErr;
- }
-
- // Initialize a bunch of managers.
- if (err == noErr)
- {
- InitGraf ((Ptr) &(gpAVTTrafficLightAppData->qdGlobals.thePort));
- InitFonts ();
- InitWindows ();
- InitMenus ();
- InitDialogs (nil);
- InitCursor ();
- }
-
- // Create our menu bar using the defs in our resources.
- if (err == noErr)
- {
- hMenuBarResource = GetNewMBar (kMenuBarResourceID);
- if (hMenuBarResource != nil)
- {
- SetMenuBar (hMenuBarResource);
- DisposeHandle (hMenuBarResource);
- AppendResMenu (GetMenuHandle (kAppleMenuID), 'DRVR');
- DrawMenuBar ();
- }
- else
- {
- err = memFullErr;//zzz what should it really be?
- }
- }
-
- // Get rects for lights.
- if (err == noErr)
- {
- hRectResource = GetResource ('RECT', kStopRectResourceID);
- if (hRectResource != nil)
- {
- gpAVTTrafficLightAppData->stopRect = *((Rect *) (*hRectResource));
- ReleaseResource (hRectResource);
- }
- else
- {
- err = ResError ();
- if (err == noErr)
- err = resNotFound;
- }
-
- if (err == noErr)
- {
- hRectResource = GetResource ('RECT', kGoRectResourceID);
- if (hRectResource != nil)
- {
- gpAVTTrafficLightAppData->goRect = *((Rect *) (*hRectResource));
- ReleaseResource (hRectResource);
- }
- else
- {
- err = ResError ();
- if (err == noErr)
- err = resNotFound;
- }
- }
- }
-
- // Create open application event handler.
- if (err == noErr)
- {
- gpAVTTrafficLightAppData->openApplicationEventHandler =
- NewAEEventHandlerProc (HandleOpenApplicationEvent);
- if (gpAVTTrafficLightAppData->openApplicationEventHandler == nil)
- err = memFullErr;
- }
-
- // Install handler.
- if (err == noErr)
- {
- err = AEInstallEventHandler
- (kCoreEventClass,
- kAEOpenApplication,
- gpAVTTrafficLightAppData->openApplicationEventHandler,
- (long) gpAVTTrafficLightAppData,
- false);
- if (err == noErr)
- {
- gpAVTTrafficLightAppData->openApplicationEventHandlerInstalled =
- true;
- }
- }
-
- // Create open documents event handler.
- if (err == noErr)
- {
- gpAVTTrafficLightAppData->openDocumentsEventHandler =
- NewAEEventHandlerProc (HandleOpenDocumentsEvent);
- if (gpAVTTrafficLightAppData->openDocumentsEventHandler == nil)
- err = memFullErr;
- }
-
- // Install handler.
- if (err == noErr)
- {
- err = AEInstallEventHandler
- (kCoreEventClass,
- kAEOpenDocuments,
- gpAVTTrafficLightAppData->openDocumentsEventHandler,
- (long) gpAVTTrafficLightAppData,
- false);
- if (err == noErr)
- {
- gpAVTTrafficLightAppData->openDocumentsEventHandlerInstalled =
- true;
- }
- }
-
- // Create print documents event handler.
- if (err == noErr)
- {
- gpAVTTrafficLightAppData->printDocumentsEventHandler =
- NewAEEventHandlerProc (HandlePrintDocumentsEvent);
- if (gpAVTTrafficLightAppData->printDocumentsEventHandler == nil)
- err = memFullErr;
- }
-
- // Install handler.
- if (err == noErr)
- {
- err = AEInstallEventHandler
- (kCoreEventClass,
- kAEPrintDocuments,
- gpAVTTrafficLightAppData->printDocumentsEventHandler,
- (long) gpAVTTrafficLightAppData,
- false);
- if (err == noErr)
- {
- gpAVTTrafficLightAppData->printDocumentsEventHandlerInstalled =
- true;
- }
- }
-
- // Create quit application event handler.
- if (err == noErr)
- {
- gpAVTTrafficLightAppData->quitApplicationEventHandler =
- NewAEEventHandlerProc (HandleQuitApplicationEvent);
- if (gpAVTTrafficLightAppData->quitApplicationEventHandler == nil)
- err = memFullErr;
- }
-
- // Install handler.
- if (err == noErr)
- {
- err = AEInstallEventHandler
- (kCoreEventClass,
- kAEQuitApplication,
- gpAVTTrafficLightAppData->quitApplicationEventHandler,
- (long) gpAVTTrafficLightAppData,
- false);
- if (err == noErr)
- {
- gpAVTTrafficLightAppData->quitApplicationEventHandlerInstalled =
- true;
- }
- }
-
- // Create device added event handler.
- if (err == noErr)
- {
- gpAVTTrafficLightAppData->deviceAddedEventHandler =
- NewAEEventHandlerProc (HandleDeviceAddedEvent);
- if (gpAVTTrafficLightAppData->deviceAddedEventHandler == nil)
- err = memFullErr;
- }
-
- // Install handler.
- if (err == noErr)
- {
- err = AEInstallEventHandler
- (kAEAVTransportEventClass,
- kAEAVTransportDeviceAdded,
- gpAVTTrafficLightAppData->deviceAddedEventHandler,
- (long) gpAVTTrafficLightAppData,
- false);
- if (err == noErr)
- {
- gpAVTTrafficLightAppData->deviceAddedEventHandlerInstalled =
- true;
- }
- }
-
- // Create device removed event handler.
- if (err == noErr)
- {
- gpAVTTrafficLightAppData->deviceRemovedEventHandler =
- NewAEEventHandlerProc (HandleDeviceRemovedEvent);
- if (gpAVTTrafficLightAppData->deviceRemovedEventHandler == nil)
- err = memFullErr;
- }
-
- // Install handler.
- if (err == noErr)
- {
- err = AEInstallEventHandler
- (kAEAVTransportEventClass,
- kAEAVTransportDeviceRemoved,
- gpAVTTrafficLightAppData->deviceRemovedEventHandler,
- (long) gpAVTTrafficLightAppData,
- false);
- if (err == noErr)
- {
- gpAVTTrafficLightAppData->deviceRemovedEventHandlerInstalled =
- true;
- }
- }
-
- // Register with the AV transport control driver family.
- if (err == noErr)
- {
- err = RegisterAVTClientApplication
- (&(gpAVTTrafficLightAppData->avtClientID),
- (UInt32) gpAVTTrafficLightAppData);
- }
-
- // Get list of drivers.
- //zzz theoretically, new ones can be added while we're doing this.
- if (err == noErr)
- err = GetAVTDriverList (nil, 0, &numAVTDrivers);
-
- if ((err == noErr) && (numAVTDrivers > 0))
- {
- avtDriverIDList = (AVTDriverID *)
- NewPtr (numAVTDrivers * sizeof (AVTDriverID));
- if (avtDriverIDList != nil)
- {
- err = GetAVTDriverList
- (avtDriverIDList, numAVTDrivers, &numAVTDrivers);
- }
- else
- {
- err = memFullErr;
- }
- }
-
- // Create a stop light for each driver.
- for (driverNum = 0;
- ((driverNum < numAVTDrivers) && (err == noErr));
- driverNum++)
- {
- err = CreateTrafficLight (avtDriverIDList[driverNum]);
- }
-
- // Allocate a buffer for video dumps.
- if (err == noErr)
- {
- dumpBuffer = NewPtr (kDumpBufferSize);
- if (dumpBuffer != nil)
- {
- gpAVTTrafficLightAppData->dumpBuffer = dumpBuffer;
- gpAVTTrafficLightAppData->dumpBufferSize = kDumpBufferSize;
- }
- else
- {
- err = memFullErr;
- }
- }
-
- // Clean up.
- if (avtDriverIDList != nil)
- DisposePtr ((Ptr) avtDriverIDList);
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // QuitApplication
- //
- // This routine quits the application.
- //
-
- static OSErr QuitApplication(void)
- {
- TrafficLightDataPtr pTrafficLightData,
- pNextTrafficLightData;
- AVTClientID avtClientID;
- OSErr err = noErr;
-
- if (gpAVTTrafficLightAppData != nil)
- {
- // Deallocate video dump buffer.
- if (gpAVTTrafficLightAppData->dumpBuffer != nil)
- DisposePtr (gpAVTTrafficLightAppData->dumpBuffer);
-
- // Remove all of the traffic lights.
- pTrafficLightData = gpAVTTrafficLightAppData->trafficLightDataList;
- while (pTrafficLightData != nil)
- {
- pNextTrafficLightData = pTrafficLightData->pNextTrafficLightData;
-
- RemoveTrafficLight (pTrafficLightData->avtDriverID);
-
- pTrafficLightData = pNextTrafficLightData;
- }
-
- // Unregister with the AV transport control driver family.
- avtClientID = gpAVTTrafficLightAppData->avtClientID;
- if (avtClientID != kInvalidAVTClientID)
- UnregisterAVTClientApplication (avtClientID);
-
- // Uninstall Apple event handlers.
- // Uninstall device removed event handler.
- if (gpAVTTrafficLightAppData->deviceRemovedEventHandlerInstalled)
- {
- AERemoveEventHandler
- (kAEAVTransportEventClass,
- kAEAVTransportDeviceRemoved,
- gpAVTTrafficLightAppData->deviceRemovedEventHandler,
- false);
- }
-
- if (gpAVTTrafficLightAppData->deviceRemovedEventHandler != nil)
- {
- DisposeRoutineDescriptor
- (gpAVTTrafficLightAppData->deviceRemovedEventHandler);
- }
-
- // Uninstall device added event handler.
- if (gpAVTTrafficLightAppData->deviceAddedEventHandlerInstalled)
- {
- AERemoveEventHandler
- (kAEAVTransportEventClass,
- kAEAVTransportDeviceAdded,
- gpAVTTrafficLightAppData->deviceAddedEventHandler,
- false);
- }
-
- if (gpAVTTrafficLightAppData->deviceAddedEventHandler != nil)
- {
- DisposeRoutineDescriptor
- (gpAVTTrafficLightAppData->deviceAddedEventHandler);
- }
-
- // Uninstall quit application event handler.
- if (gpAVTTrafficLightAppData->quitApplicationEventHandlerInstalled)
- {
- AERemoveEventHandler
- (kCoreEventClass,
- kAEQuitApplication,
- gpAVTTrafficLightAppData->quitApplicationEventHandler,
- false);
- }
-
- if (gpAVTTrafficLightAppData->quitApplicationEventHandler != nil)
- {
- DisposeRoutineDescriptor
- (gpAVTTrafficLightAppData->quitApplicationEventHandler);
- }
-
- // Uninstall print documents event handler.
- if (gpAVTTrafficLightAppData->printDocumentsEventHandlerInstalled)
- {
- AERemoveEventHandler
- (kCoreEventClass,
- kAEPrintDocuments,
- gpAVTTrafficLightAppData->printDocumentsEventHandler,
- false);
- }
-
- if (gpAVTTrafficLightAppData->printDocumentsEventHandler != nil)
- {
- DisposeRoutineDescriptor
- (gpAVTTrafficLightAppData->printDocumentsEventHandler);
- }
-
- // Uninstall open documents event handler.
- if (gpAVTTrafficLightAppData->openDocumentsEventHandlerInstalled)
- {
- AERemoveEventHandler
- (kCoreEventClass,
- kAEOpenDocuments,
- gpAVTTrafficLightAppData->openDocumentsEventHandler,
- false);
- }
-
- if (gpAVTTrafficLightAppData->openDocumentsEventHandler != nil)
- {
- DisposeRoutineDescriptor
- (gpAVTTrafficLightAppData->openDocumentsEventHandler);
- }
-
- // Uninstall open application event handler.
- if (gpAVTTrafficLightAppData->openApplicationEventHandlerInstalled)
- {
- AERemoveEventHandler
- (kCoreEventClass,
- kAEOpenApplication,
- gpAVTTrafficLightAppData->openApplicationEventHandler,
- false);
- }
-
- if (gpAVTTrafficLightAppData->openApplicationEventHandler != nil)
- {
- DisposeRoutineDescriptor
- (gpAVTTrafficLightAppData->openApplicationEventHandler);
- }
-
- // Dispose of global data record.
- DisposePtr ((Ptr) gpAVTTrafficLightAppData);
- gpAVTTrafficLightAppData = nil;
-
- // Set event loop to quit.
- quitTrafficLightApp = true;
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // CreateTrafficLight
- //
- // This routine creates a new traffic light window for the given driver.
- //
-
- static OSErr CreateTrafficLight(
- AVTDriverID avtDriverID)
- {
- WindowRef trafficLightWindowRef = kInvalidWindowRef;
- TrafficLightDataPtr pTrafficLightData = nil;
- OSErr err = noErr;
-
- // Get a new stop light window.
- trafficLightWindowRef =
- GetNewWindow (kTrafficLightWindowResourceID, nil, (WindowRef) -1);
- if (trafficLightWindowRef == kInvalidWindowRef)
- err = -1;//zzz not really correct.
-
- // Allocate traffic light data record.
- if (err == noErr)
- {
- pTrafficLightData =
- (TrafficLightDataPtr) NewPtrClear (sizeof (TrafficLightData));
- if (pTrafficLightData != nil)
- {
- pTrafficLightData->trafficLightWindowRef = trafficLightWindowRef;
- pTrafficLightData->avtDriverID = avtDriverID;
- pTrafficLightData->stopped = true;
- }
- else
- {
- err = memFullErr;
- }
- }
-
- // Open connection to driver.
- if (err == noErr)
- err = OpenAVTDriver (avtDriverID);
-
- // Store traffic light data in window ref con.
- if (err == noErr)
- SetWRefCon (trafficLightWindowRef, (long) pTrafficLightData);
-
- // Add traffic light to list or clean up on error.
- if (err == noErr)
- {
- pTrafficLightData->pNextTrafficLightData =
- gpAVTTrafficLightAppData->trafficLightDataList;
- gpAVTTrafficLightAppData->trafficLightDataList =
- pTrafficLightData;
- }
- else
- {
- if (pTrafficLightData != nil)
- DisposePtr ((Ptr) pTrafficLightData);
-
- if (trafficLightWindowRef != kInvalidWindowRef)
- CloseWindow (trafficLightWindowRef);
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // RemoveTrafficLight
- //
- // This routine removes the traffic light window for the given driver.
- //
-
- static OSErr RemoveTrafficLight(
- AVTDriverID avtDriverID)
- {
- TrafficLightDataPtr pTrafficLightData;
- Boolean found;
- OSErr err = noErr;
-
- // Find traffic light for given driver.
- pTrafficLightData = FindTrafficLightFromAVTDriver (avtDriverID);
- if (pTrafficLightData != nil)
- found = true;
- else
- found = false;
-
- // Stop playing snap shot.
- if (found)
- {
- if (pTrafficLightData->snapShotPlaying)
- StopSnapShot ();
- }
-
- // Close connection to driver.
- if (found)
- CloseAVTDriver (avtDriverID);
-
- // Close the traffic light window.
- if (found)
- CloseWindow (pTrafficLightData->trafficLightWindowRef);
-
- // Remove the traffic light data from our list.
- if (found)
- RemoveTrafficLightFromList (pTrafficLightData);
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // CloseTrafficLightWindow
- //
- // This routine closes the given traffic light window.
- //
-
- static OSErr CloseTrafficLightWindow(
- WindowRef windowRef)
- {
- TrafficLightDataPtr pTrafficLightData;
- OSErr err = noErr;
-
- // Get traffic light data.
- pTrafficLightData = (TrafficLightDataPtr) GetWRefCon (windowRef);
-
- // Remove the traffic light.
- err = RemoveTrafficLight (pTrafficLightData->avtDriverID);
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // DrawTrafficLight
- //
- // This routine draws the given traffic light window.
- //
-
- static OSErr DrawTrafficLight(
- WindowRef windowRef)
- {
- TrafficLightDataPtr pTrafficLightData;
- GrafPtr pWindowPort;
- OSErr err = noErr;
-
- // Get traffic light data.
- pTrafficLightData = (TrafficLightDataPtr) GetWRefCon (windowRef);
-
- // Get window's graf port.
- pWindowPort = (GrafPtr) GetWindowPort (windowRef);
-
- // Set port to the window's port.
- SetPortWindowPort (windowRef);
-
- // Clear window.
- EraseRect (&(pWindowPort->portRect));
-
- // Draw stop light.
- if (pTrafficLightData->stopped)
- ForeColor (redColor);
- else
- ForeColor (blackColor);
- PaintOval (&(gpAVTTrafficLightAppData->stopRect));
- ForeColor (blackColor);
- FrameOval (&(gpAVTTrafficLightAppData->stopRect));
-
- // Draw go light.
- if (pTrafficLightData->stopped)
- ForeColor (blackColor);
- else
- ForeColor (greenColor);
- PaintOval (&(gpAVTTrafficLightAppData->goRect));
- ForeColor (blackColor);
- FrameOval (&(gpAVTTrafficLightAppData->goRect));
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // SetTrafficLightState
- //
- // This routine sets the state of the given traffic light window.
- //
-
- static OSErr SetTrafficLightState(
- WindowRef windowRef,
- Boolean stopped)
- {
- TrafficLightDataPtr pTrafficLightData;
- AVTPlayParams avtPlayParams;
- AVTStopParams avtStopParams;
- GrafPtr pWindowPort;
- OSErr err = noErr;
-
- // Get traffic light data.
- pTrafficLightData = (TrafficLightDataPtr) GetWRefCon (windowRef);
-
- // Do something only if the state has changed.
- if (stopped != pTrafficLightData->stopped)
- {
- if (stopped)
- {
- avtStopParams.avtInterfaceParams.interfaceSelector =
- kAVTransportStop;
- err = CallAVTDriver
- (pTrafficLightData->avtDriverID,
- (AVTInterfaceParamsPtr) &avtStopParams);
- }
- else
- {
- avtPlayParams.avtInterfaceParams.interfaceSelector =
- kAVTransportPlay;
- err = CallAVTDriver
- (pTrafficLightData->avtDriverID,
- (AVTInterfaceParamsPtr) &avtPlayParams);
- }
-
- // Set new state.
- if (err == noErr)
- pTrafficLightData->stopped = stopped;
-
- // Force window update.
- if (err == noErr)
- {
- pWindowPort = (GrafPtr) GetWindowPort (windowRef);
- SetPortWindowPort (windowRef);
- InvalRect (&(pWindowPort->portRect));
- }
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // GetTrafficLightState
- //
- // This routine gets the state of the given traffic light window.
- //
-
- static Boolean GetTrafficLightState(
- WindowRef windowRef)
- {
- TrafficLightDataPtr pTrafficLightData;
-
- // Get traffic light data.
- pTrafficLightData = (TrafficLightDataPtr) GetWRefCon (windowRef);
-
- return (pTrafficLightData->stopped);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // UpdateWindow
- //
- // This routine updates the given window.
- //
-
- static OSErr UpdateWindow(
- WindowRef windowRef)
- {
- Boolean updateNeeded,
- preparedUpdate;
- OSErr err = noErr;
-
- // Prepare window for updating.
- err = PrepareWindowForUpdating (windowRef, &updateNeeded);
- if (err == noErr)
- preparedUpdate = true;
- else
- preparedUpdate = false;
-
- // Draw the window.
- if ((err == noErr) && (updateNeeded))
- err = DrawTrafficLight (windowRef);
-
- // Release the window from updating.
- if (preparedUpdate)
- ReleaseWindowFromUpdating (windowRef);
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // UpdateMenus
- //
- // This routine sets up the menus for the front most window.
- //
-
- static OSErr UpdateMenus(void)
- {
- WindowRef windowRef;
- MenuHandle hMenu;
- OSErr err = noErr;
-
- // Get reference to front most window.
- windowRef = FrontWindow ();
-
- // Get handle to file menu.
- hMenu = GetMenuHandle (kFileMenuID);
-
- // Close menu item should be enabled if there is a window open.
- if (windowRef != kInvalidWindowRef)
- EnableItem (hMenu, kCloseFileMenuItem);
- else
- DisableItem (hMenu, kCloseFileMenuItem);
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // UpdateCursor
- //
- // This routine sets the cursor to the correct image for the given mouse
- // position.
- //
-
- static OSErr UpdateCursor(
- Point mousePosition,
- RgnHandle hCursorRgn)
- {
- WindowRef windowRef;
- GrafPtr pWindowPort;
- Rect windowPortRect;
- RgnHandle hArrowCursorRgn = nil,
- hPlusCursorRgn = nil;
- OSErr err = noErr;
-
- // Update if we're not in background.
- if (gpAVTTrafficLightAppData->inForeground)
- {
- // Get reference to front most window.
- windowRef = FrontWindow ();
-
- // Initialize cursor regions.
- hArrowCursorRgn = NewRgn ();
- hPlusCursorRgn = NewRgn ();
-
- // Set plus region to front most window if it's a traffic light.
- if (IsTrafficLightWindow (windowRef))
- {
- // Get window's port and port rect.
- pWindowPort = (GrafPtr) GetWindowPort (windowRef);
-
- // Set plus region to visible portion of traffic light window.
- SetPortWindowPort (windowRef);
- SetOrigin (-(pWindowPort->portBits.bounds.left),
- -(pWindowPort->portBits.bounds.top));
- windowPortRect = pWindowPort->portRect;
- RectRgn (hPlusCursorRgn, &windowPortRect);
- SectRgn (hPlusCursorRgn, pWindowPort->visRgn, hPlusCursorRgn);
- SetOrigin (0, 0);
- }
-
- // Set arrow region to everywhere except the other cursor regions.
- SetRectRgn (hArrowCursorRgn,
- kExtremeNeg,
- kExtremeNeg,
- kExtremePos,
- kExtremePos);
- DiffRgn (hArrowCursorRgn, hPlusCursorRgn, hArrowCursorRgn);
-
- // Change the cursor image and region.
- if (PtInRgn (mousePosition, hPlusCursorRgn))
- {
- SetCursor (*GetCursor (plusCursor));
- CopyRgn (hPlusCursorRgn, hCursorRgn);
- }
- else
- {
- SetCursor (&(gpAVTTrafficLightAppData->qdGlobals.arrow));
- CopyRgn (hArrowCursorRgn, hCursorRgn);
- }
- }
-
- // Clean up.
- if (hArrowCursorRgn != nil)
- DisposeRgn (hArrowCursorRgn);
- if (hPlusCursorRgn != nil)
- DisposeRgn (hPlusCursorRgn);
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // IsTrafficLightWindow
- //
- // This routine returns true if the given window is a traffic light.
- //
-
- static Boolean IsTrafficLightWindow(
- WindowRef windowRef)
- {
- // If the window is a user window, it's a traffic light.
- if (GetWindowKind (windowRef) == kApplicationWindowKind)
- return (true);
- else
- return (false);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // GetMousePosition
- //
- // This routine returns the current position of the mouse.
- //
-
- static void GetMousePosition(
- Point *pMousePosition)
- {
- EventRecord eventRecord;
-
- // Get mouse position from event manager.
- OSEventAvail (0, &eventRecord);
- *pMousePosition = eventRecord.where;
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleOpenApplicationEvent
- //
- // This routine handles open application events.
- //
-
- static pascal OSErr HandleOpenApplicationEvent(
- AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefcon)
- {
- OSErr err = noErr;
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleOpenDocumentsEvent
- //
- // This routine handles open documents events.
- //zzz should we return an error?
- //
-
- static pascal OSErr HandleOpenDocumentsEvent(
- AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefcon)
- {
- OSErr err = noErr;
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandlePrintDocumentsEvent
- //
- // This routine handles print documents events.
- //zzz should we return an error?
- //
-
- static pascal OSErr HandlePrintDocumentsEvent(
- AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefcon)
- {
- OSErr err = noErr;
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleQuitApplicationEvent
- //
- // This routine handles quit application events.
- //
-
- static pascal OSErr HandleQuitApplicationEvent(
- AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefcon)
- {
- OSErr err = noErr;
-
- // Quit the application.
- QuitApplication ();
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleDeviceAddedEvent
- //
- // This routine handles AV transport control device added events.
- //
-
- static pascal OSErr HandleDeviceAddedEvent(
- AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefcon)
- {
- AVTDriverID avtDriverID;
- DescType returnedType;
- Size returnedSize;
- Boolean inList;
- OSErr err = noErr;
-
- // Get driver ID from apple event.
- err = AEGetParamPtr (theAppleEvent,
- kAEAVTDriverIDKey,
- kAEAVTDriverIDType,
- &returnedType,
- &avtDriverID,
- sizeof (AVTDriverID),
- &returnedSize);
-
- // Check if avt driver is in our list. This will happen if device was
- // connected, opened, disconnected, and reconnected without being closed.
- // If it's in our list, do not create a new traffic light.
- if (err == noErr)
- {
- if (FindTrafficLightFromAVTDriver (avtDriverID))
- inList = true;
- else
- inList = false;
- }
-
- // Create traffic light for added device.
- if ((err == noErr) && (!inList))
- err = CreateTrafficLight (avtDriverID);
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleDeviceRemovedEvent
- //
- // This routine handles AV transport control device removed events.
- //
-
- static pascal OSErr HandleDeviceRemovedEvent(
- AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefcon)
- {
- AVTDriverID avtDriverID;
- DescType returnedType;
- Size returnedSize;
- OSErr err = noErr;
-
- // Get driver ID from apple event.
- err = AEGetParamPtr (theAppleEvent,
- kAEAVTDriverIDKey,
- kAEAVTDriverIDType,
- &returnedType,
- &avtDriverID,
- sizeof (AVTDriverID),
- &returnedSize);
-
- // Create traffic light for removed device.
- if (err == noErr)
- err = RemoveTrafficLight (avtDriverID);
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // FindTrafficLightFromAVTDriver
- //
- // This routine searches for the traffic light corresponding to the given
- // AVT driver ID.
- //
-
- static TrafficLightDataPtr FindTrafficLightFromAVTDriver(
- AVTDriverID avtDriverID)
- {
- TrafficLightDataPtr pTrafficLightData,
- pPrevTrafficLightData;
- Boolean found;
- OSErr err = noErr;
-
- // Find traffic light for given driver.
- pTrafficLightData = gpAVTTrafficLightAppData->trafficLightDataList;
- pPrevTrafficLightData = nil;
- found = false;
- while ((pTrafficLightData != nil) && (!found))
- {
- if (pTrafficLightData->avtDriverID == avtDriverID)
- {
- found = true;
- }
- else
- {
- pPrevTrafficLightData = pTrafficLightData;
- pTrafficLightData = pTrafficLightData->pNextTrafficLightData;
- }
- }
-
- return (pTrafficLightData);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // RemoveTrafficLightFromList
- //
- // This routine removes the given traffic light data record from our list.
- //
-
- static OSErr RemoveTrafficLightFromList(
- TrafficLightDataPtr pTrafficLightData)
- {
- TrafficLightDataPtr pSearchTrafficLightData,
- pPrevTrafficLightData;
- Boolean found;
- OSErr err = noErr;
-
- // Find previous traffic light data record.
- pSearchTrafficLightData = gpAVTTrafficLightAppData->trafficLightDataList;
- pPrevTrafficLightData = nil;
- found = false;
- while ((pSearchTrafficLightData != nil) && (!found))
- {
- if (pSearchTrafficLightData == pTrafficLightData)
- {
- found = true;
- }
- else
- {
- pPrevTrafficLightData = pSearchTrafficLightData;
- pSearchTrafficLightData = pSearchTrafficLightData->pNextTrafficLightData;
- }
- }
-
- // Remove the traffic light data from our list.
- if (found)
- {
- if (pPrevTrafficLightData != nil)
- {
- pPrevTrafficLightData->pNextTrafficLightData =
- pTrafficLightData->pNextTrafficLightData;
- }
- else
- {
- gpAVTTrafficLightAppData->trafficLightDataList =
- pTrafficLightData->pNextTrafficLightData;
- }
-
- DisposePtr ((Ptr) pTrafficLightData);
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Window managing routines.
- //
- // Code that needs to use window records goes here.
- //
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // PrepareWindowForUpdating
- //
- // This routine prepares the given window for updating.
- //
-
- static OSErr PrepareWindowForUpdating(
- WindowRef windowRef,
- Boolean *pUpdateNeeded)
- {
- GrafPtr pWindowPort;
- OSErr err = noErr;
-
- // Get window's port.
- pWindowPort = (GrafPtr) GetWindowPort (windowRef);
-
- // Call window manager to begin update.
- BeginUpdate (windowRef);
-
- // Check if window needs updating.
- if (pUpdateNeeded != nil)
- {
- if (EmptyRgn (pWindowPort->visRgn))
- *pUpdateNeeded = false;
- else
- *pUpdateNeeded = true;
- }
-
- return (err);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // ReleaseWindowFromUpdating
- //
- // This routine releases the given window from updating.
- //
-
- static OSErr ReleaseWindowFromUpdating(
- WindowRef windowRef)
- {
- OSErr err = noErr;
-
- // Call window manager to end update.
- EndUpdate (windowRef);
-
- return (err);
- }
-